package com.ruoyi.web.controller.system;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysRoleField;
import com.ruoyi.system.service.ISysRoleFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字段角色Controller
 * 
 * @author ruoyi
 * @date 2023-03-13
 */
@RestController
@RequestMapping("/system/field/test")
public class SysRoleFieldController extends BaseController
{
    @Autowired
    private ISysRoleFieldService sysRoleFieldService;

    /**
     * 查询字段角色列表
     */
    @PreAuthorize("@ss.hasPermi('system:field:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRoleField sysRoleField)
    {
        startPage();
        List<SysRoleField> list = sysRoleFieldService.selectSysRoleFieldList(sysRoleField);
        return getDataTable(list);
    }

    /**
     * 导出字段角色列表
     */
    @GetMapping("/export")
    public AjaxResult export(SysRoleField sysRoleField)
    {
        List<SysRoleField> list = sysRoleFieldService.selectSysRoleFieldList(sysRoleField);
        ExcelUtil<SysRoleField> util = new ExcelUtil<SysRoleField>(SysRoleField.class);
        return util.exportExcel(list, "field");
    }

    /**
     * 获取字段角色详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:field:query')")
    @GetMapping(value = "/{fieldId}")
    public AjaxResult getInfo(@PathVariable("fieldId") Long fieldId)
    {
        return AjaxResult.success(sysRoleFieldService.selectSysRoleFieldById(fieldId));
    }

    /**
     * 新增字段角色
     */
    @PostMapping
    public AjaxResult add(@RequestBody SysRoleField sysRoleField)
    {
        return toAjax(sysRoleFieldService.insertSysRoleField(sysRoleField));
    }

    /**
     * 修改字段角色
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SysRoleField sysRoleField)
    {
        return toAjax(sysRoleFieldService.updateSysRoleField(sysRoleField));
    }

    /**
     * 删除字段角色
     */
	@DeleteMapping("/{fieldIds}")
    public AjaxResult remove(@PathVariable Long[] fieldIds)
    {
        return toAjax(sysRoleFieldService.deleteSysRoleFieldByIds(fieldIds));
    }
}
